﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace NHTrace
{
  public class HtmlMessageRenderer
  {
    private StringBuilder _preContent;
    private StringBuilder _postContent;

    public HtmlMessageRenderer(string templateFile)
    {
      string template = File.ReadAllText(templateFile);
      template = template.Replace("{templatePath}", Path.GetDirectoryName(templateFile));

      string preContent = template.Substring(0, template.IndexOf("{content}"));
      string postContent = template.Substring(template.IndexOf("{content}") + "{content}".Length);

      _preContent = new StringBuilder(preContent);
      _postContent = new StringBuilder(postContent);
    }

    private string getHtml(StringBuilder messages)
    {
      return _preContent.ToString() + messages.ToString() + _postContent.ToString();
    }

    public void Render(WebBrowserEx bowser, StringBuilder messages)
    {
      bowser.DocumentText = getHtml(messages);
    }
  }
}
